<div class="layui-fluid">
    <div class="layui-breadcrumb jy-breadcrumb">

    </div>
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto" lay-filter="LAY-list-form">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">操作人</label>
                    <div class="layui-input-block">
                        <select name="operator" xm-select="operator" xm-select-search="/index/User/getUserByName"
                                xm-select-radio="">
                        </select>
                    </div>
                </div>
                <div class="layui-inline ">
                    <label class="layui-form-label">操作时间</label>
                    <div class="layui-input-block layui-jy-datetime">
                        <input type="text" class="layui-input" id="date" name="operate_time" placeholder="">
                    </div>
                </div>

                <div class="layui-inline">
                    <button class="layui-btn search" lay-submit lay-filter="LAY-list-search">查询</button>
                </div>
            </div>
        </div>

        <div class="layui-card-body">
            <table id="LAY-list" lay-filter="LAY-list"></table>
            <!-- 行内工具 -->
            <script type="text/html" id="LAY-list-toolbar">
                {{# if(d.file_url&&d.source_file_url){ var fileName='下载错误信息';}else{ var fileName='下载导出文件' } }}

                {{# if(d.file_url){ }}
                <a class="layui-btn layui-btn-normal layui-btn-xs" href="{{d.file_url}}">{{fileName}}</a>
                {{# } }}
                {{# if(d.msg){ }}
                <br/>
                <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="detail" >查看错误信息</a>
                {{# } }}

            </script>
        </div>
    </div>
</div>
<script type="text/html" id="subTableHtml">
    <table   class="layui-table">
        <thead>
        <tr>
            <th>错误信息</th>
        </tr>
        </thead>
        <tbody>
        {{#  for(var i in d){ }}
        <tr>
            <td>{{d[i].msg}}</td>
        </tr>
        {{#  } }}
        </tbody>
    </table>
</script>
<style>
    .layui-table-cell {
        height: auto;
    }
     .layui-layer.layui-layer-undefined{
         overflow: auto;
     }
</style>
<script>
    layui.use(['admin', 'table', 'form', 'toolJ', 'formSelects', 'laydate','laytpl'], function () {
        var $ = layui.$
            , admin = layui.admin
            , view = layui.view
            , table = layui.table
            , laytpl = layui.laytpl
            , laydate = layui.laydate
            , formSelects = layui.formSelects
            , toolJ = layui.toolJ
            , form = layui.form;
        form.render(null, 'LAY-list-form');
        laydate.render({
            elem: '#date'
            , type: 'datetime'
            , range: true
        });
        formSelects.render();
        //用户管理
        table.render({
            elem: '#LAY-list'
            , url: '/index/Queue/index'
            , cellMinWidth: 80
            ,where:{
                "operator":layui.data(layui.setter.tableName).access_token
            }
            , cols: [[
                {field: 'id', title: 'ID', width: 70}
                , {field: 'stateName', title: '状态', width: 80}
                , {field: 'resultName', title: '处理结果', width: 100}
                , {
                    field: 'file_name', title: '结果文件名称', templet: function (d) {
                        if (d.file_url) {
                            return '<a lay-event="detail" class="blue"  href="' + d.file_url + '">' + d.file_name + '</a>';
                        } else {
                            return d.file_name;
                        }
                    }
                }
                , {
                    field: 'source_file_name', title: '导入文件名称', templet: function (d) {
                        if (d.source_file_url) {
                            return '<a class="blue"  href="' + d.source_file_url + '">' + d.source_file_name + '</a>';
                        } else {
                            return d.source_file_name;
                        }
                    }
                }
                , {field: 'moduleName', title: '模块'}
                , {field: 'operatorName', title: '操作人', width: 80}
                , {field: 'operate_time', title: '操作时间'}
                , {field: 'complete_time', title: '完成时间'}
                , {title: '操作', align: 'center', width: 120, toolbar: '#LAY-list-toolbar'}
            ]]
            , page: true
            , limit: 15
            , text: {none: '暂无相关数据!'}
        });
        var u={};
        u[layui.data(layui.setter.tableName).access_token]=layui.data(layui.setter.tableName).cn_name;
        toolJ.formSelectsArr(u, 'operator',[layui.data(layui.setter.tableName).access_token]);


        //监听行内操作
        table.on('tool(LAY-list)', function (obj) {
            var data = obj.data;

            switch (obj.event) {
                case 'detail':
                    var getTpl = subTableHtml.innerHTML;
                    var that=$(this);
                    try{
                        var m=JSON.parse(data.msg);
                    }catch (e) {
                       toolJ.error('错误信息过多,请下载文件查看!');
                       return false;
                    }
                    laytpl(getTpl).render(m, function (html) {
                        layer.open({
                            type: 5,
                            title: '查看',
                            shade: [0.5, '#000'],
                            offset: 'auto',
                            area: ["60%", "85%"],
                            shadeClose: true,
                            closeBtn: 1,
                            anim: 2,
                            content: html,
                            cancel: function () {
                            }
                        });

                    });
                    break;
            }
        })
    });
</script>